package ve.ejb.entity;

import ve.ejb.metadata.Dimension;
import ve.ejb.metadata.Settings;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import ve.ejb.metadata.Category;

/**
 *
 * @author memozac
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED )
public abstract class ScoreCard implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue(strategy = GenerationType.AUTO) protected Long idScoreCard;

    @OneToOne private Settings settings;

    @OneToOne private Agreement agreement;

    @OneToMany private Collection<ActionPlan> actionPlans;

    @OneToMany private Collection<Panel> panels;

    @ManyToOne private Person responsible;

    @ManyToMany(targetEntity=ScoreCard.class) @JoinTable(name="ScoreCardRelation", joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idOtherScoreCard")) private Collection<ScoreCard> scoreCards;

    @ManyToMany(targetEntity=ScoreCard.class) @JoinTable(name="ScoreCardRelation", joinColumns=@JoinColumn(name="idOtherScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idScoreCard")) private Collection<ScoreCard> otherScoreCards;

    @ManyToMany(targetEntity=Category.class) @JoinTable(name="ScoreCardCategory", joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idCategory")) private Collection<Category> categories;
    
    @ManyToMany(targetEntity=Dimension.class) @JoinTable(name="ScoreCardDimension", joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idDimension")) private Collection<Dimension> dimensions;

    @ManyToMany(targetEntity=ScoreDomain.class) @JoinTable(name="ScoreCardDomain", joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idScoreDomain")) private Collection<ScoreDomain> scoreDomains;

    @ManyToMany(targetEntity=Person.class) @JoinTable(name="Alert", joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idPerson")) private Collection<Person> suscribers;

    @Column(columnDefinition="text") private String name;
    
    @Column(columnDefinition="text") private String description;

    @Temporal(value = TemporalType.TIMESTAMP) private Date registerDate;

    public Date getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<Person> getSuscribers() {
        return suscribers;
    }

    public void setSuscribers(Collection<Person> suscribers) {
        this.suscribers = suscribers;
    }

    public Collection<Panel> getPanels() {
        return panels;
    }

    public void setPanels(Collection<Panel> panels) {
        this.panels = panels;
    }

    public Agreement getAgreement() {
        return agreement;
    }

    public void setAgreement(Agreement agreement) {
        this.agreement = agreement;
    }

    public Person getResponsible() {
        return responsible;
    }

    public void setResponsible(Person responsible) {
        this.responsible = responsible;
    }
    

    public Collection<ScoreDomain> getScoreDomains() {
        return scoreDomains;
    }

    public void setScoreDomains(Collection<ScoreDomain> scoreDomains) {
        this.scoreDomains = scoreDomains;
    }

   public Settings getSettings() {
        return settings;
    }

    public void setSettings(Settings settings) {
        this.settings = settings;
    }

    public Collection<ActionPlan> getActionPlans() {
        return actionPlans;
    }

    public void setActionPlans(Collection<ActionPlan> actionPlans) {
        this.actionPlans = actionPlans;
    }

    public Collection<Category> getCategories() {
        return categories;
    }

    public void setCategories(Collection<Category> categories) {
        this.categories = categories;
    }

    public Collection<Dimension> getDimensions() {
        return dimensions;
    }

    public void setDimensions(Collection<Dimension> dimensions) {
        this.dimensions = dimensions;
    }

    public Long getIdScoreCard() {
        return idScoreCard;
    }

    public void setIdScoreCard(Long idScoreCard) {
        this.idScoreCard = idScoreCard;
    }

    public Collection<ScoreCard> getOtherScoreCards() {
        return otherScoreCards;
    }

    public void setOtherScoreCards(Collection<ScoreCard> otherScoreCards) {
        this.otherScoreCards = otherScoreCards;
    }

    public Collection<ScoreCard> getScoreCards() {
        return scoreCards;
    }

    public void setScoreCards(Collection<ScoreCard> scoreCards) {
        this.scoreCards = scoreCards;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idScoreCard != null ? idScoreCard.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ScoreCard)) {
            return false;
        }
        ScoreCard other = (ScoreCard) object;
        if ((this.idScoreCard == null && other.idScoreCard != null) || (this.idScoreCard != null && !this.idScoreCard.equals(other.idScoreCard))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ve.ejb.entity.ScoreCard[id=" + idScoreCard + "]";
    }

}
